#ifndef _VIEW_PORT_H
#define _VIEW_PORT_H
#include <d3dx9.h>
#include "QRectangle.h"

class ViewPort
{
private:
	static D3DXVECTOR2 _Position;

	static int _Width; //screen width
	static int _Height;    //screen height
	static int _MapWidth;  
	static int _MapHeight; 

public:
	ViewPort::ViewPort(D3DXVECTOR2 Position, int Width, int Height, int MapWidth, int MapHeight)
	{
		_Position = Position;
		_Width = Width;
		_Height = Height;
		_MapWidth = MapWidth;
		_MapHeight = MapHeight;
	} 
	~ViewPort();

	 static QRectangle GetBound()
	{
		return QRectangle(_Position.x, _Position.y, (float)_Width, (float)_Height);
	}

	 static int MapWidth()
	 {
		 return _MapWidth;
	 }
	 static int MapHeight()
	 {
		 return _MapHeight;
	 }

	void ViewPort::Move(D3DXVECTOR2 NewPosition)
	{
		D3DXVECTOR2 Delta = D3DXVECTOR2((float)NewPosition.x - _Position.x, (float)NewPosition.y - _Position.y);
		if(NewPosition.x >= 0)
		{
			if(getRight() + Delta.x <= _MapWidth)
				_Position.x += Delta.x;
			else
				setRight(_MapWidth);
		}
		else
		{
			if(getLeft() + Delta.x >= 0)
				_Position.x += Delta.x;
			else
				_Position.x = 0;
		}

		if(NewPosition.y >= 0)
		{
			if(_Position.y + _Height + Delta.y <= _MapHeight)
				_Position.y += Delta.y;
			else
				_Position.y = (float)_MapHeight - _Height;
		}
		else
		{
			if(_Position.y + Delta.y >= 0)
				_Position.y += Delta.y;
			else
				_Position.y = 0;
		}
	}

	void setRight(int Right)
	{
		_Position.x = (float)(Right - _Width);
	}
	void setBottom(int Bottom)
	{
		_Position.y = (float)(Bottom - _Height); 
	}

	float getTop()
	{
		return _Position.y;
	}
	float getLeft()
	{
		return _Position.x;
	}
	float getRight()
	{
		return _Position.x + _Width;
	}
	float getBottom()
	{
		return _Position.y + _Height;
	}
};

#endif